package baseTest;

import java.util.ArrayList;
import java.util.List;

class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
     TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }
public class isSymmetric {
    public static void main(String[] args) {
        TreeNode treeNode = new TreeNode(1);
        treeNode.right = new TreeNode(2);
        treeNode.left = new TreeNode(2);
        treeNode.left.left = new TreeNode(3);
        treeNode.left.right = new TreeNode(4);
        treeNode.right.left = new TreeNode(4);
        treeNode.right.right = new TreeNode(3);
        System.out.println(process(treeNode));
    }
    public static boolean process(TreeNode root){
        List<Integer> lList = new ArrayList<Integer>();
        List<Integer> rList = new ArrayList<Integer>();
        return process(root,lList,rList);
    }
    public static boolean process(TreeNode root,List<Integer> lList,List<Integer> rList){
        if (root.left == null){
            return true;
        }
        if (root.right == null){
            return false;
        }
        process(root.left,lList,rList);
        lList.add(root.left.val);
        lList.add(root.right.val);
        process(root.right,lList,rList);
        rList.add(root.right.val);
        rList.add(root.left.val);


        for (int i = 0; i < lList.size(); i++) {
            if (rList.get(i) != lList.get(i)){
                return false;
            }
            System.out.println(rList.get(i) + " " + lList.get(i));
        }
        return true;
    }

}
